<!DOCTYPE html>












  


<html class="theme-next mist use-motion" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">


























<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">

<link rel="stylesheet" href="/css/main.css?v=6.7.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=6.7.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/uploads/favicon.ico?v=6.7.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/uploads/favicon.ico?v=6.7.0">


  <link rel="mask-icon" href="/images/logo.svg?v=6.7.0" color="#222">







<script id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '6.7.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="一 需求说明 需求1:hexo快速迁机.hexo的源文件是存放在一台主机上的.而到了后期迁机会带来一系列麻烦,不是很方便.需要寻找一种能快速迁机的方法. 需求2:让百度收录hexo页面.我之前hexo生成的静态文件是发布到github上的,考虑到github禁止百度抓取网页,导致百度将不能收录博客上的文章.需要实现百度能抓取网站收录的方法.">
<meta name="keywords" content="hexo迁移,hexo迁机,gitlab博客,gitpages百度收录">
<meta property="og:type" content="article">
<meta property="og:title" content="「linux」hexo基于docker上运行,并发表到gitlab">
<meta property="og:url" content="/2018/10/13/【linux】迁移hexo到docker并发表到gitlab上/index.html">
<meta property="og:site_name" content="吴楚衡">
<meta property="og:description" content="一 需求说明 需求1:hexo快速迁机.hexo的源文件是存放在一台主机上的.而到了后期迁机会带来一系列麻烦,不是很方便.需要寻找一种能快速迁机的方法. 需求2:让百度收录hexo页面.我之前hexo生成的静态文件是发布到github上的,考虑到github禁止百度抓取网页,导致百度将不能收录博客上的文章.需要实现百度能抓取网站收录的方法.">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="/images/pasted-1.png">
<meta property="og:image" content="/images/20181016004526.png">
<meta property="og:image" content="/images/201810172047.png">
<meta property="og:image" content="/images/20181017211401.png">
<meta property="og:image" content="/images/20181017211401110.png">
<meta property="og:updated_time" content="2020-04-10T13:09:57.171Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="「linux」hexo基于docker上运行,并发表到gitlab">
<meta name="twitter:description" content="一 需求说明 需求1:hexo快速迁机.hexo的源文件是存放在一台主机上的.而到了后期迁机会带来一系列麻烦,不是很方便.需要寻找一种能快速迁机的方法. 需求2:让百度收录hexo页面.我之前hexo生成的静态文件是发布到github上的,考虑到github禁止百度抓取网页,导致百度将不能收录博客上的文章.需要实现百度能抓取网站收录的方法.">
<meta name="twitter:image" content="/images/pasted-1.png">






  <link rel="canonical" href="/2018/10/13/【linux】迁移hexo到docker并发表到gitlab上/">



<script id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>「linux」hexo基于docker上运行,并发表到gitlab | 吴楚衡</title>
  












  <noscript>
  <style>
  .use-motion .motion-element,
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-title { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta custom-logo">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">吴楚衡</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
      
        <h1 class="site-subtitle" itemprop="description">来找我吧！我的目标是星辰大海！</h1>
      
    
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">

    
    
    
      
    

    
      
    

    <a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-archives">

    
    
    
      
    

    
      
    

    <a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档<span class="badge">99</span></a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">

    
    
    
      
    

    
      
    

    <a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签<span class="badge">77</span></a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">

    
    
    
      
    

    
      
    

    <a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类<span class="badge">17</span></a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-about">

    
    
    
      
    

    
      
    

    <a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-历史">

    
    
    
      
    

    
      
    

    <a href="/history/" rel="section"><i class="menu-item-icon fa fa-fw fa-history"></i> <br>历史</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-书单">

    
    
    
      
    

    
      
    

    <a href="/book-list/index.html" rel="section"><i class="menu-item-icon fa fa-fw fa-book"></i> <br>书单</a>

  </li>
        
        
        
          
          <li class="menu-item menu-item-工具">

    
    
    
      
    

    
      
    

    <a href="/tool-list/index.html" rel="section"><i class="menu-item-icon fa fa-fw fa-book"></i> <br>工具</a>

  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="/2018/10/13/【linux】迁移hexo到docker并发表到gitlab上/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="吴楚衡">
      <meta itemprop="description" content="IT菜鸟,写这个博客是防止未来把自己学习的东西给忘记了,也是为了自己学习的那点东西做下总结加深下印象,请多指教^_^!">
      <meta itemprop="image" content="/uploads/favicon.ico">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="吴楚衡">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">「linux」hexo基于docker上运行,并发表到gitlab<span class="exturl post-edit-link" data-url="aHR0cHM6Ly9naXRodWIuY29tL3d1Y2h1aGVuZy9oZXhvL3RyZWUvbWFzdGVyL3NvdXJjZS9fcG9zdHMvX3Bvc3RzL+OAkGxpbnV444CR6L+B56e7aGV4b+WIsGRvY2tlcuW5tuWPkeihqOWIsGdpdGxhYuS4ii5tZA==" title="编辑"><i class="fa fa-pencil"></i></span>

              
            
          </h2>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-10-13 18:48:06" itemprop="dateCreated datePublished" datetime="2018-10-13T18:48:06+08:00">2018-10-13</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2020-04-10 21:09:57" itemprop="dateModified" datetime="2020-04-10T21:09:57+08:00">2020-04-10</time>
              
            
          </span>

          

          
            
            
              
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
            
                <a href="/2018/10/13/【linux】迁移hexo到docker并发表到gitlab上/#comments" itemprop="discussionUrl">
                  <span class="post-meta-item-text">评论数：</span> <span class="post-comments-count valine-comment-count" data-xid="/2018/10/13/【linux】迁移hexo到docker并发表到gitlab上/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="post-meta-item-icon">
            <i class="fa fa-eye"></i>
             阅读次数： 
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><img src="/images/pasted-1.png" alt="upload successful"></p>
<h4 id="一-需求说明"><a href="#一-需求说明" class="headerlink" title="一 需求说明"></a>一 需求说明</h4><ul>
<li>需求1:<code>hexo</code>快速迁机.<code>hexo</code>的源文件是存放在一台主机上的.而到了后期迁机会带来一系列麻烦,不是很方便.需要寻找一种能快速迁机的方法.</li>
<li>需求2:让百度收录<code>hexo</code>页面.我之前<code>hexo</code>生成的静态文件是发布到<code>github</code>上的,考虑到<code>github</code>禁止百度抓取网页,导致百度将不能收录博客上的文章.需要实现百度能抓取网站收录的方法.<a id="more"></a>
</li>
</ul>
<h5 id="1-需求解决方案说明"><a href="#1-需求解决方案说明" class="headerlink" title="1 需求解决方案说明."></a>1 需求解决方案说明.</h5><h6 id="1-1-关于”hexo快速迁机”实现说明"><a href="#1-1-关于”hexo快速迁机”实现说明" class="headerlink" title="1.1 关于”hexo快速迁机”实现说明."></a>1.1 关于”<code>hexo</code>快速迁机”实现说明.</h6><p>&emsp;<code>hexo</code>基于<code>docker</code>可以实现快速迁机.流程操作步骤如下(点击查看实例):<br>&emsp;&emsp; <a href="#1.1.1" target="_self">1.1.1 配置<code>dockerfile</code>文件并构建<code>hexo</code>项目;</a><br>&emsp;&emsp; <a href="#1.1.2" target="_self">1.1.2 收集迁机所需要的文件;</a><br>&emsp;&emsp; <a href="#1.1.3" target="_self">1.1.3 迁机测试;</a><br>&emsp;&emsp; <a href="#1.1.4" target="_self">1.1.4 迁机小结和讨论;</a>    </p>
<h6 id="1-2-关于”让百度收录hexo页面”实现说明"><a href="#1-2-关于”让百度收录hexo页面”实现说明" class="headerlink" title="1.2 关于”让百度收录hexo页面”实现说明."></a>1.2 关于”让百度收录<code>hexo</code>页面”实现说明.</h6><p>&emsp;由于<code>gitlab</code>是允许百度抓取的,所以将发布到<code>github</code>的页面改为<code>gitab</code>,实现百度收录.</p>
<ul>
<li>注:由于这个时间不够,只能下次再补上<code>gitlab</code>的相关教程了,这里是<code>gitlab</code>的<span class="exturl" data-url="aHR0cHM6Ly9naXRsYWIuY29tL3BhZ2VzL2hleG8=" title="https://gitlab.com/pages/hexo"><code>hexo</code>官方教程<i class="fa fa-external-link"></i></span>,把例子拉下来再把<code>markdown</code>和主题挂上去再推送上去就行了,嗯,就这简单</li>
</ul>
<h5 id="2-准备工作"><a href="#2-准备工作" class="headerlink" title="2 准备工作"></a>2 准备工作</h5><ul>
<li>安装好<code>docker</code>工具,没有安装的可以参考<span class="exturl" data-url="aHR0cHM6Ly95ZWFzeS5naXRib29rcy5pby9kb2NrZXJfcHJhY3RpY2UvaW1hZ2UvcHVsbC5odG1s" title="https://yeasy.gitbooks.io/docker_practice/image/pull.html">docker-从入门到实踐<i class="fa fa-external-link"></i></span>进行安装;</li>
<li>一个<code>gitlab</code>帐号,没有帐号去<span class="exturl" data-url="aHR0cHM6Ly9hYm91dC5naXRsYWIuY29t" title="https://about.gitlab.com"><code>gitlab</code>官网<i class="fa fa-external-link"></i></span>注册.</li>
</ul>
<h5 id="3-方案最终实现的理想结果"><a href="#3-方案最终实现的理想结果" class="headerlink" title="3 方案最终实现的理想结果"></a>3 方案最终实现的理想结果</h5><p>&emsp; 在任意一台安装<code>docker</code>且联网的主机上导入打包好的源码文件,一键自动化完成迁移,并实现在容器中发布能被百度收录的网站,实现快捷完全迁机,并且跟原来原来宿主主机的环境基本一致.</p>
<ul>
<li>整个源码文件+<code>docke</code>构建文件,用一条命令在已经安装好<code>docker</code>且能联网的主机上，自动化构建镜像完成全部自动化布署。由于我已经预见结果了，就先说下成功总结:由于镜像是由<code>dockfile</code>构建的非黑盒镜像，<code>dockefile</code>几乎不占用空间，而且<code>hexo</code>需要的依赖库由于会在构建时自动化下载，可以在源码文件中删除掉。所以整个项目的迁移大小其实就是你写的一些<code>markdown</code>文本和静态文件加上一个40多M的<code>hexo</code>框架,整个迁机的过程是非常轻量化的，操作很方便。</li>
</ul>
<h4 id="二-好，开干"><a href="#二-好，开干" class="headerlink" title="二 好，开干"></a>二 好，开干</h4><h5 id="实例-1-1-1-配置dockerfile文件并构建hexo项目"><a href="#实例-1-1-1-配置dockerfile文件并构建hexo项目" class="headerlink" title="实例:1.1.1 配置dockerfile文件并构建hexo项目;"></a>实例:<span id="1.1.1">1.1.1 配置<code>dockerfile</code>文件并构建<code>hexo</code>项目;</span></h5><p>&emsp;新建一个任意目录并进入,这里用<code>hexo</code>目录做演示<code>mkdir hexo &amp;&amp; cd  hexo;</code>.以下是<code>Dockerfile</code>构建文件内容并保存起来,也可以根据自己的需求来定制.</p>
<div class="highlight-wrap" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="BASH"><figure class="iseeu highlight /bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">        <span class="comment">#基于debian 8.8</span></span><br><span class="line">FROM    node:8.2.0</span><br><span class="line">        <span class="comment"># 安装hexo推送依赖git工具</span></span><br><span class="line">RUN     apt-get upgrade -y  \</span><br><span class="line">        &amp;&amp; apt-get -y install git \</span><br><span class="line">        <span class="comment">#git用户名,如:</span></span><br><span class="line">        &amp;&amp; git config  --global user.name <span class="string">"wuchuheng"</span> \</span><br><span class="line">        <span class="comment">#git用户email,如:</span></span><br><span class="line">        &amp;&amp; git config  --global user.email <span class="string">"wuchuheng@163.com"</span> \</span><br><span class="line">        <span class="comment"># 淘宝npm镜像</span></span><br><span class="line">        &amp;&amp; npm install -g cnpm --registry=https://registry.npm.taobao.org \</span><br><span class="line">        <span class="comment"># 安装hexo命令行工具</span></span><br><span class="line">        &amp;&amp; cnpm install -g hexo-cli \</span><br><span class="line">        <span class="comment">#初始化hexo项目目录,置于/hexo</span></span><br><span class="line">        &amp;&amp; hexo init /hexo &amp;&amp; <span class="built_in">cd</span> /hexo \</span><br><span class="line">        <span class="comment">#根据自己喜好来安装插件,如:</span></span><br><span class="line">        <span class="comment">#git 插件用于推送到仓库,必备插件之一,</span></span><br><span class="line">        &amp;&amp; cnpm install hexo-deployer-git --save \</span><br><span class="line">        <span class="comment">#RRS功能插件</span></span><br><span class="line">        &amp;&amp; cnpm install hexo-generator-feed --save \</span><br><span class="line">        <span class="comment">#next主题本地搜索插件,查找资料很管用不用next主题的可以不用</span></span><br><span class="line">        &amp;&amp; cnpm install hexo-generator-searchdb --savea \</span><br><span class="line">        <span class="comment">#安装next主题,如果不喜欢默认主题就选择自己喜欢的来安装</span></span><br><span class="line">        &amp;&amp; git <span class="built_in">clone</span> https://github.com/theme-next/hexo-theme-next /hexo/themes/next \</span><br><span class="line">        <span class="comment">#next 本地搜索</span></span><br><span class="line">        &amp;&amp; cnpm install hexo-generator-searchdb --save;</span><br><span class="line"></span><br><span class="line">WORKDIR /hexo</span><br><span class="line"></span><br><span class="line">EXPOSE 4000</span><br><span class="line"></span><br><span class="line">ENTRYPOINT [<span class="string">"hexo"</span>,<span class="string">"server"</span>]</span><br></pre></td></tr></table></figure></div>
<p>&emsp;保存好构建文件<code>Dockerfile</code>,目录<code>hexo</code>下执行命令开始构建镜像:<br><div class="highlight-wrap" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="BASH"><figure class="iseeu highlight /bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo systemctl start docker.servic; <span class="comment"># 启动docker</span></span><br><span class="line">sudo docker build -t hexo:0.1 . ;   <span class="comment"># 本地构建自定义镜像hexo 0.1</span></span><br></pre></td></tr></table></figure></div></p>
<p><code>suodo docker images;</code>查看已经生成的镜像:<br><img src="/images/20181016004526.png" alt="镜像列表"></p>
<h5 id="实例-1-1-2-收集迁机所需要的文件"><a href="#实例-1-1-2-收集迁机所需要的文件" class="headerlink" title="实例:1.1.2 收集迁机所需要的文件"></a>实例:<span id="1.1.2">1.1.2 收集迁机所需要的文件</span></h5><p>&emsp;统一的<code>rsa</code>文件能确保<code>hexo</code>发布问题.本地<code>hexo</code>目录下将本地<code>rsa</code>文件复制<code>cp ~/.ssh ./ -r ;</code>;如没有<code>.ssh</code>目录,就 <code>ssh-keygen -t rsa -C &quot;&quot; ;</code>一路回车就行,然后重复上面操作.<code>hexo</code>结果目录如下.<br><img src="/images/201810172047.png" alt="镜像列表"><br>&emsp;现在要将容器中的<code>hexo</code>目录下的<code>source</code>和<code>themes</code>目录和<code>_config.yml</code>导出来到本地迁机目录<code>hexo</code>下.<br><div class="highlight-wrap" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" contenteditable="true" data-rel="BASH"><figure class="iseeu highlight /bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo docker run -it -v <span class="variable">$PWD</span>/tmp/:/tmp --name hexo hexo:0.1 /bin/bash ;</span><br><span class="line">cp -r /hexo/<span class="built_in">source</span>/ /hexo/_config.yml  /hexo/themes/ /tmp ;</span><br></pre></td></tr></table></figure></div></p>
<p><img src="/images/20181017211401.png" alt="收集迁机文件"></p>
<h5 id="实例-1-1-3-迁机测试"><a href="#实例-1-1-3-迁机测试" class="headerlink" title="实例:1.1.3 迁机测试;"></a>实例:<span id="1.1.3">1.1.3 迁机测试;</span></h5><p>&emsp;说明下:这里的迁机是指将本地的<code>.ssh</code>目录,<code>source</code>目录,<code>_config.yml</code>文件,<code>themes</code>目录通过<code>Dockerfile</code>将<code>hexo</code>的整个运行环境在容器给构建出来,然后再把我们的这个文章的源数据<code>source</code>,<code>themes</code>主题目录,用于推送的密钥<code>.ssh</code>和<code>hexo</code>配置文件<code>_config.yml</code>给挂载到容器对应的位置中去.然后在容器中启动<code>hexo</code>就行了.也就是说要迁机只要把这挂载的几个文件和目录以及这个<code>Dockerfile</code>给拿走就行了,其它的就不用管,它们会通过<code>Dockerfile</code>去生成就行了.真正实现了轻量级迁机.<br>&emsp;启动一个新的容器并将<code>hexo</code>目录下的文件对应挂载到容器上,映射<code>4000</code>端口;<code>sudo docker run -itd  -v $PWD/source/:/hexo/source/ -v $PWD/_config.yml:/hexo/_config.yml   -v $PWD/themes/:/hexo/themes -v $PWD/.ssh/:/root/.ssh/  --privileged=true --name hexo_debug -p 4000:4000 hexo:0.2 /bin/bash ;</code><br><img src="/images/20181017211401110.png" alt="启动容器"><br> 而当我在其它的主机生成容器成功运行,并能正常浏览迁机前的文章,说明我的这个想法是可行的.</p>
<h5 id="实例-1-1-4-迁机讨论和小结"><a href="#实例-1-1-4-迁机讨论和小结" class="headerlink" title="实例:1.1.4 迁机讨论和小结"></a>实例:<span id="1.1.4">1.1.4 迁机讨论和小结</span></h5><p> &emsp;回顾下整个流程,有点绕是第2步的收集迁机文件,有3个地方可能会困惑:1一个是:我们需要构建出<code>hexo</code>的容器,从容器里给复制到临时的挂载目录<code>tmp</code>,再从容器外面把文件给收集起来,那为什么不能直接从容器中导出来呢?答案是否定的!如果要从容器中原本的文件导出来,我目前也就发现这种方法而已.<br>&emsp;另一个是:<code>.ssh</code>目录?这个很好解释,如果我们不使用统一的密钥,到时候迁机要推送数据的时候又要去生成一个密钥再加到代码仓库那边,很麻烦,所以就算进迁机文件中了.<br>&emsp;最后一个是:<code>themes</code>主题目录?这个也很好解释为什么要加入到迁机目录中.如果我们使用别人的主题的话.这个主题文件是在构建容器的同时下载下来的.由于每个主题的都有着它们的配置文件,要配置才能使用,那就会出现每次迁机都要去主题配置一下,不如算进迁机文件中,这样就再也不用再次去配置了,而且也规避了一个版本风险,其实主题在迭代同时也可能会带来配置改变,同样的配置在新的主题版本不一定有用,导致<code>hexo</code>运行,无疑增加学习成本.不如选一个主题版本配置后,算进迁机上目录中.<br>&emsp;说到版本迭代,这种轻量级迁机可能会存在一个版本迭代的风险,只是有可能^_^! <code>hexo</code>它有一个配置<code>_config.yml</code>文件算在迁机文件中的所以它是不变的.但每次在构建镜像时都是下载最新版本<code>hexo</code>,如有一天迁机文件<code>_config.yml</code>配置不能满足新版本的话,可能会导致<code>hexo</code>不能正常启动.这是个问题,如果你有解决的方法也可以告诉我下,但愿我不要遇到它.<br>  当然你也可以把整个容器镜像也导出来,这样就不会出现这样的可能了.</p>

      
    </div>

    

    
    
    

    

    
      
    
    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/uploads/pay/wechatpay.png" alt="吴楚衡 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/uploads/pay/alipay.png" alt="吴楚衡 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/docker/" rel="tag"># docker</a>
          
            <a href="/tags/hexo/" rel="tag"># hexo</a>
          
            <a href="/tags/gitlab/" rel="tag"># gitlab</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/10/11/【linux】构思手稿-去中心化shell翻译工具trans/" rel="next" title="「linux」构思手稿- 去中心化shell翻译工具trans">
                <i class="fa fa-chevron-left"></i> 「linux」构思手稿- 去中心化shell翻译工具trans
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/11/09/【linux】nginx笔记-入手准备/" rel="prev" title="「nginx」nginx笔记-入手准备">
                「nginx」nginx笔记-入手准备 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>


  </div>


          </div>
          

  
    <div class="comments" id="comments">
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/uploads/favicon.ico" alt="吴楚衡">
            
              <p class="site-author-name" itemprop="name">吴楚衡</p>
              <p class="site-description motion-element" itemprop="description">IT菜鸟,写这个博客是防止未来把自己学习的东西给忘记了,也是为了自己学习的那点东西做下总结加深下印象,请多指教^_^!</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/archives/">
                
                    <span class="site-state-item-count">99</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">16</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">76</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3d1Y2h1aGVuZw==" title="GitHub &rarr; https://github.com/wuchuheng"><i class="fa fa-fw fa-github"></i>GitHub</span>
                </span>
              
                <span class="links-of-author-item">
                  
                  
                    
                  
                  
                    
                  
                  <span class="exturl" data-url="bWFpbHRvOmFkbWluQHd1Y2h1aGVuZy5jb20=" title="E-Mail &rarr; mailto:admin@wuchuheng.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
                </span>
              
            </div>
          

          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9oZXhvLmlvL3poLWNuL2RvY3MvaW5kZXguaHRtbA==" title="https://hexo.io/zh-cn/docs/index.html">hexo文档</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cDovL3RoZW1lLW5leHQuaWlzc25hbi5jb20=" title="http://theme-next.iissnan.com">主题文档</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cDovL3d3dy5saW51eGV5ZS5jb20=" title="http://www.linuxeye.com">linux学习平台</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9naXQtc2NtLmNvbS9ib29rL3poL3Yy" title="https://git-scm.com/book/zh/v2">git使用手册</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9oaWdobGlnaHRqcy5vcmc=" title="https://highlightjs.org">highlightjs</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9odWIuZG9ja2VyLmNvbS91L3d1Y2h1aGVuZy8=" title="https://hub.docker.com/u/wuchuheng/">docker</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cDovL3hpYW9oYW55dS5tZQ==" title="http://xiaohanyu.me">cnlox</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cDovL3hpYW9oYW55dS5tZQ==" title="http://xiaohanyu.me">vim从入门到精通</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9jaWtlYmxvZy5jb20v" title="https://cikeblog.com/">刺客博客</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9oeWRpbmdzeS5naXRodWIuaW8v" title="https://hydingsy.github.io/">算法牛人</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cDovL3hhcmdpbi5jb20vcmVhZGluZ3Mv" title="http://xargin.com/readings/">牛人</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9lYm9va2ZvdW5kYXRpb24uZ2l0aHViLmlvL2ZyZWUtcHJvZ3JhbW1pbmctYm9va3Mv" title="https://ebookfoundation.github.io/free-programming-books/">githhub开源书</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9sYWlqdy5jb20v" title="https://laijw.com/">赖经纬</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly93dzRrLmNvbS8=" title="https://ww4k.com/">徐庆业</span>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <span class="exturl" data-url="aHR0cHM6Ly9oYXNhaWsuY29tLw==" title="https://hasaik.com/">next主题参考</span>
                  </li>
                
              </ul>
            </div>
          

          
            
          
          

        </div>
      </div>

      
      <!--noindex-->
        <div class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
            
            
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#一-需求说明"><span class="nav-text">一 需求说明</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1-需求解决方案说明"><span class="nav-text">1 需求解决方案说明.</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#1-1-关于”hexo快速迁机”实现说明"><span class="nav-text">1.1 关于”hexo快速迁机”实现说明.</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#1-2-关于”让百度收录hexo页面”实现说明"><span class="nav-text">1.2 关于”让百度收录hexo页面”实现说明.</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-准备工作"><span class="nav-text">2 准备工作</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3-方案最终实现的理想结果"><span class="nav-text">3 方案最终实现的理想结果</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#二-好，开干"><span class="nav-text">二 好，开干</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-1-1-1-配置dockerfile文件并构建hexo项目"><span class="nav-text">实例:1.1.1 配置dockerfile文件并构建hexo项目;</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-1-1-2-收集迁机所需要的文件"><span class="nav-text">实例:1.1.2 收集迁机所需要的文件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-1-1-3-迁机测试"><span class="nav-text">实例:1.1.3 迁机测试;</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#实例-1-1-4-迁机讨论和小结"><span class="nav-text">实例:1.1.4 迁机讨论和小结</span></a></li></ol></li></ol></div>
            

          </div>
        </div>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">  <span class="exturl" data-url="aHR0cDovL3d3dy5taWl0YmVpYW4uZ292LmNu">粤ICP备17071471号 </span>&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">吴楚衡</span>

  

  
</div>


  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> 强力驱动 v3.9.0</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 – <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Mist</span> v6.7.0</div>





  <script src="https://unpkg.com/mermaid@7.1.2/dist/mermaid.min.js"></script>
    <script>
        if (window.mermaid) {
            mermaid.initialize("");
        }
  </script>



        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="post-meta-item-icon">
      <i class="fa fa-user"></i>
    </span>
    <span class="site-uv" title="总访客量">
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
    </span>
  

  
    <span class="post-meta-divider">|</span>
  

  
    <span class="post-meta-item-icon">
      <i class="fa fa-eye"></i>
    </span>
    <span class="site-pv" title="总访问量">
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
    </span>
  
</div>









        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

    

    
  </div>

  

<script>
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  <script src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>


  


  <script src="/js/src/utils.js?v=6.7.0"></script>

  <script src="/js/src/motion.js?v=6.7.0"></script>



  
  


  <script src="/js/src/schemes/muse.js?v=6.7.0"></script>




  
  <script src="/js/src/scrollspy.js?v=6.7.0"></script>
<script src="/js/src/post-details.js?v=6.7.0"></script>



  


  <script src="/js/src/bootstrap.js?v=6.7.0"></script>



  
  

<script src="//cdn1.lncld.net/static/js/3.11.1/av-min.js"></script>



<script src="//unpkg.com/valine/dist/Valine.min.js"></script>

<script>
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'vUPCRqeu7bXvUdFGGLuT3zvs-gzGzoHsz',
    appKey: 'cooQBOkOaV3XE3SP4ihtaWOe',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false
  });
</script>




  


  

  <script>
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url).replace(/\/{2,}/g, '/');
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x"></i></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x"></i></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  

  

  

  

  

  
  <script src="/js/src/exturl.js?v=6.7.0"></script>


  

  
  <style>
    .copy-btn {
      display: inline-block;
      padding: 6px 12px;
      font-size: 13px;
      font-weight: 700;
      line-height: 20px;
      color: #333;
      white-space: nowrap;
      vertical-align: middle;
      cursor: pointer;
      background-color: #eee;
      background-image: linear-gradient(#fcfcfc, #eee);
      border: 1px solid #d5d5d5;
      border-radius: 3px;
      user-select: none;
      outline: 0;
    }

    .highlight-wrap .copy-btn {
      transition: opacity .3s ease-in-out;
      opacity: 0;
      padding: 2px 6px;
      position: absolute;
      right: 4px;
      top: 8px;
    }

    .highlight-wrap:hover .copy-btn,
    .highlight-wrap .copy-btn:focus {
      opacity: 1
    }

    .highlight-wrap {
      position: relative;
    }
  </style>
  <script>
    $('.highlight').each(function(i, e) {
      var $wrap = $('<div>').addClass('highlight-wrap');
      $(e).after($wrap);
      $wrap.append($('<button>').addClass('copy-btn').append('复制').on('click', function(e) {
        var code = $(this).parent().find('.code').find('.line').map(function(i, e) {
          return $(e).text();
        }).toArray().join('\n');
        var ta = document.createElement('textarea');
        var range = document.createRange(); //For Chrome
        var sel = window.getSelection(); //For Chrome
        var yPosition = window.pageYOffset || document.documentElement.scrollTop;
        ta.style.top = yPosition + 'px'; //Prevent page scroll
        ta.style.position = 'absolute';
        ta.style.opacity = '0';
        ta.value = code;
        ta.textContent = code; //For FireFox
        ta.contentEditable = true;
        ta.readOnly = false;
        document.body.appendChild(ta);
        range.selectNode(ta);
        sel.removeAllRanges();
        sel.addRange(range);
        ta.setSelectionRange(0, code.length);
        var result = document.execCommand('copy');
        
          if (result) $(this).text('复制成功');
          else $(this).text('复制失败');
        
        ta.blur(); //For iOS
        $(this).blur();
      })).on('mouseleave', function(e) {
        var $b = $(this).find('.copy-btn');
        setTimeout(function() {
          $b.text('复制');
        }, 300);
      }).append(e);
    })
  </script>


  

</body>
</html>
